﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Heroius.WpfClock
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
            MouseDown += Window_MouseDown;

            timer = new Timer();
            timer.Interval = 100;
            timer.Elapsed += Timer_Elapsed;

            DataContext = this;

            timer.Start();
        }

        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var dt = DateTime.Now;
            Hour = (dt.Hour + dt.Minute/60.0) * 30;
            Minute = (dt.Minute + dt.Second / 60.0) * 6;
            Second = (dt.Second + dt.Millisecond / 1000.0) * 6;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Hour"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Minute"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Second"));
        }

        Timer timer;

        public event PropertyChangedEventHandler PropertyChanged;

        public double Hour { get; set; }
        public double Minute { get; set; }
        public double Second { get; set; }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }

        private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Close();
        }
    }
}
